package com.tjing.frame.controller;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ExecutionException;

import javax.servlet.http.HttpServletRequest;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.tjing.bussiness.model.*;
import com.tjing.frame.model.User;
import common.tool;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONArray;
import com.tjing.frame.model.Navi;
import com.tjing.frame.services.DbServices;
import com.tjing.frame.util.CodeHelper;
import util.Constants;
import util.HttpUtils;
import util.PayUtil;
import util.XmlUtil;

@Controller
@RequestMapping(value="/public/common")
public class CommonController {

	@Autowired
	private DbServices dbservices;

	@RequestMapping("/r")
	public ModelAndView r(@RequestParam String page, @RequestParam String naviId, HttpServletRequest request) {
		List<MathMenu> allButtons = dbservices.findList("MathMenu", "{pid:" + naviId + "}", "");
		//String sql = "select n.* from ((tj_navi n join tj_role_navi rn on n.id=rn.navi_id) join tj_role r on r.id=rn.role_id) join tj_user_role ur on ur.role_id=r.id where n.parent_id=? and ur.user_id=? group by n.id order by n.orderno ,n.id";
		String sql = "select * from math_menu where pid=? order by Sort";
		HashMap<Integer, Object> paramMap = new HashMap<Integer, Object>();
		paramMap.put(0, naviId);
		//paramMap.put(1, CodeHelper.getCurrentUser().getId());
		List<MathMenu> buttons = dbservices.findListBySql(sql, paramMap, MathMenu.class);
		//按钮权限规则：如果在菜单下添加了按钮记录，但是没有出现在权限表中，则隐藏
		JSONArray forbitBtns = new JSONArray();
		for (MathMenu mathMenu : allButtons) {
			if (!buttons.contains(mathMenu)) {
				forbitBtns.add(mathMenu.getPageUrl());
			}
		}
		ModelAndView mav = new ModelAndView();
		mav.addObject("forbitBtns", forbitBtns);
		mav.setViewName(page);
		return mav;
	}

	@RequestMapping("/r2")
	public ModelAndView r2(@RequestParam String page, HttpServletRequest request) {
		ModelAndView mav = new ModelAndView();
		mav.setViewName(page);
		return mav;
	}

	@RequestMapping("/readySalePrintCommon")
	public ModelAndView readySalePrintCommon(HttpServletRequest request) throws ExecutionException {
		ModelAndView mav = new ModelAndView();
		mav.getModel().put("theaterId", "1");
		mav.setViewName("sell/job/theatre_print");
		return mav;
	}

	@RequestMapping("/readySalePrintCommon2")
	public ModelAndView readySalePrintCommon2(HttpServletRequest request) throws ExecutionException {
		ModelAndView mav = new ModelAndView();
		mav.getModel().put("theaterId", "2");
		mav.setViewName("sell/job/theatre_print2");
		return mav;
	}

	@RequestMapping("/readySalePrintCommon4CZ")
	public ModelAndView readySalePrintCommon4CZ(HttpServletRequest request) throws ExecutionException {
		String theaterId = request.getParameter("id");
		ModelAndView mav = new ModelAndView();
		mav.setViewName("sell/job/theatre_print_cz");
		mav.addObject("theaterId", theaterId);
		return mav;
	}

	//修改任务状态
	@RequestMapping("/taskStateEdit")
	public @ResponseBody Map quryaskEdit(HttpServletRequest request) {
		Date nowTime = new Date();
		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strnowTime = time.format(nowTime);

		JSONObject param = CodeHelper.getRequestParams(request);
		Integer id=param.getInteger("id");
		Integer state=param.getInteger("state");

		Map resultMap = new HashMap();
		List<JSONObject> mathQuryask = Lists.newArrayList();
		JSONObject jobj = new JSONObject();
		if(state!=1){
			jobj.put("id", id);
			jobj.put("state", state);
			jobj.put("modifyUser", CodeHelper.getCurrentUser().getId());
			jobj.put("modifyDateTime", strnowTime);
			mathQuryask.add(jobj);
			dbservices.saveOrupdateRecords("QhTask", mathQuryask, null, false);
			resultMap.put("state", "1");
			return resultMap;
		}

		QhTask qhTask=dbservices.getEntity(QhTask.class, id);
		User user=dbservices.getEntity(User.class, qhTask.getCreateUser());

		if(user.getAvailFund()>=qhTask.getInvestAmount()){
			jobj.put("id", id);
			jobj.put("state", state);
			jobj.put("modifyUser", CodeHelper.getCurrentUser().getId());
			jobj.put("modifyDateTime", strnowTime);
			mathQuryask.add(jobj);
			dbservices.saveOrupdateRecords("QhTask", mathQuryask, null, false);
			resultMap.put("state", "1");

			//添加广告主财务记录
			addAdverAccount(qhTask.getCreateUser(),qhTask.getInvestAmount());
		}
		else{
			resultMap.put("state",0);
		}

		return resultMap;
	}

	//修改域名状态
	@RequestMapping("/urlStateEdit")
	public @ResponseBody Map urlStateEdit(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		Integer id=param.getInteger("id");
		Integer state=param.getInteger("state");

		Date nowTime = new Date();
		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strnowTime = time.format(nowTime);

		Map resultMap = new HashMap();

		List<JSONObject> qhUrls = Lists.newArrayList();
		JSONObject qhUrl = new JSONObject();

		qhUrl.put("id", id);
		qhUrl.put("state", state);
		qhUrl.put("modifyUser", CodeHelper.getCurrentUser().getId());
		qhUrl.put("modifyDateTime", strnowTime);
		qhUrls.add(qhUrl);
		dbservices.saveOrupdateRecords("QhUrl", qhUrls, null, false);
		resultMap.put("state", "1");

		return resultMap;
	}

	//修改任务状态
	@RequestMapping("/taskStateEditByIds")
	public @ResponseBody Map taskStateEditByIds(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		String[] ids=param.getString("ids").split(",");
		List<Integer> idsList = Lists.newArrayList();
		for(String id:ids){
			idsList.add(Integer.valueOf(id));
		}
		Integer num=dbservices.updateStateByIds("QhTask", param.getInteger("state"), idsList);
		Map resultMap = new HashMap();
		resultMap.put("num", num);
		return resultMap;
	}

	//答疑修改状态
	@RequestMapping("/noviceTaskStateEdit")
	public @ResponseBody Map noviceTaskStateEdit(HttpServletRequest request) {
		Date nowTime = new Date();
		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strnowTime = time.format(nowTime);

		JSONObject param = CodeHelper.getRequestParams(request);
		Map resultMap = new HashMap();
		List<JSONObject> mathQuryask = Lists.newArrayList();
		JSONObject jobj = new JSONObject();

		jobj.put("id", param.getInteger("id"));
		jobj.put("state", param.getInteger("state"));
		jobj.put("modifyUser", CodeHelper.getCurrentUser().getId());
		jobj.put("modifyDateTime", strnowTime);
		mathQuryask.add(jobj);
		String returnId = dbservices.saveOrupdateRecords("QhNoviceTask", mathQuryask, null, false);
		resultMap.put("state", "1");

		return resultMap;
	}

	//修改用户状态
	@RequestMapping("/userStateEdit")
	public @ResponseBody Map userStateEdit(HttpServletRequest request) {
		Date nowTime = new Date();
		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strnowTime = time.format(nowTime);

		JSONObject param = CodeHelper.getRequestParams(request);
		Map resultMap = new HashMap();
		List<JSONObject> mathQuryask = Lists.newArrayList();
		JSONObject jobj = new JSONObject();

		jobj.put("id", param.getInteger("id"));
		jobj.put("state", param.getInteger("state"));
		jobj.put("modifyUser", CodeHelper.getCurrentUser().getId());
		jobj.put("modifyDateTime", strnowTime);
		mathQuryask.add(jobj);
		String returnId = dbservices.saveOrupdateRecords("QhUser", mathQuryask, null, false);
		resultMap.put("state", "1");

		return resultMap;
	}
	//获取徒弟人数
	@RequestMapping("/getApprentCnt")
	public @ResponseBody Map getApprentCnt(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		String srcPla=param.getString("srcPla");
		String createDateTime1=param.getString("createDateTime1");
		String createDateTime2=param.getString("createDateTime2");

		Integer i=0;
		HashMap<Integer, Object> intParamMap = new HashMap();

		String sql="select sum(ApprentCnt) from (SELECT id,(select count(0) from qh_user where IsLogin=1 and Inviter=a.mobile) as ApprentCnt from qh_user a where 1=1";
		if(srcPla!=null&&srcPla!="") {
			sql+=" and srcpla=?";
			intParamMap.put(i++, srcPla);
		}
		if(createDateTime1!=null&&createDateTime1!="") {
			sql+=" and CreateDateTime>=?";
			intParamMap.put(i++, createDateTime1);
		}
		if(createDateTime2!=null&&createDateTime2!="") {
			sql+=" and CreateDateTime<=?";
			intParamMap.put(i++, createDateTime2);
		}
		sql+=")aa";
		Object apprentCnt = dbservices.findUniqueBySql(sql, intParamMap);
		sql="select sum(TeamCnt) from (SELECT id,(select count(0) from qh_user where IsLogin=1 and LOCATE(a.id, InMobile)>0) as TeamCnt from qh_user a where 1=1";
		if(srcPla!=null&&srcPla!="") {
			sql+=" and srcpla=?";
		}
		if(createDateTime1!=null&&createDateTime1!="") {
			sql+=" and CreateDateTime>=?";
		}
		if(createDateTime2!=null&&createDateTime2!="") {
			sql+=" and CreateDateTime<=?";
		}
		sql+=")aa";
		Object teamCnt=dbservices.findUniqueBySql(sql, intParamMap);

		sql="select count(0) from qh_user a where Mobile in(select CreateUser from qh_user_operlog where round(((unix_timestamp(now()) - unix_timestamp(CreateDateTime)) / 60),0) < 60)";
		i=0;
		intParamMap.clear();
		if(createDateTime1!=null&&createDateTime1!="") {
			sql+=" and CreateDateTime>=?";
			intParamMap.put(i++, createDateTime1);
		}
		if(createDateTime2!=null&&createDateTime2!="") {
			sql+=" and CreateDateTime<=?";
			intParamMap.put(i++, createDateTime2);
		}
		Object onlineCnt=dbservices.findUniqueBySql(sql,intParamMap);

		Map resultMap = new HashMap();
		resultMap.put("apprentCnt", apprentCnt==null?0:apprentCnt);
		resultMap.put("teamCnt", teamCnt==null?0:teamCnt);
		resultMap.put("onlineCnt", onlineCnt==null?0:onlineCnt);
		return resultMap;
	}

	//修改提现状态
	@RequestMapping("/userCashStateEdit")
	public @ResponseBody Map userCashStateEdit(HttpServletRequest request) throws Exception {
		Date nowTime = new Date();
		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strnowTime = time.format(nowTime);

		JSONObject param = CodeHelper.getRequestParams(request);
        Integer id= param.getInteger("id");
		Integer state=param.getInteger("state");
		QhUserCash qhUserCash=dbservices.getEntity(QhUserCash.class, id);

		Map resultMap = new HashMap();
		List<JSONObject> mathQuryask = Lists.newArrayList();
		JSONObject jobj = new JSONObject();

		String hql="from QhUser where mobile=?";
		Integer i=0;
		HashMap<Integer, Object> intParamMap = new HashMap();
		intParamMap.put(i++, param.getString("createUser"));
		List<QhUser> qhUsers = dbservices.findListByHql(hql, intParamMap);
		String msg="";

		jobj.put("id", id);
		jobj.put("state", state);
		jobj.put("modifyUser", CodeHelper.getCurrentUser().getId());
		jobj.put("modifyDateTime", strnowTime);
		mathQuryask.add(jobj);
		dbservices.saveOrupdateRecords("QhUserCash", mathQuryask, null, false);

		resultMap.put("state", "1");

		if(state==1){
			msg=time.format(qhUserCash.getCreateDateTime()) + "提现" + qhUserCash.getCashMoney() + "元已审核通过";
		}
		else{
			msg=time.format(qhUserCash.getCreateDateTime()) + "提现" + qhUserCash.getCashMoney() + "元审核不通过";

			if(qhUsers.size()>0){
				QhUser qhUser=dbservices.getEntity(QhUser.class,qhUsers.get(0).getId());

				qhUser.setAvailFund(qhUser.getAvailFund()+qhUserCash.getCashMoney());
				dbservices.update(qhUser);
			}

		}

		ToolController.sendMsg(msg, qhUserCash.getCreateUser());

		List<JSONObject> notices = Lists.newArrayList();
		JSONObject jobnotice = new JSONObject();
		jobnotice.put("uid",qhUsers.get(0).getId());
		jobnotice.put("userType", "a");
		jobnotice.put("type", "系统消息");
		jobnotice.put("title", msg);
		jobnotice.put("note", msg);
		jobnotice.put("createUser", CodeHelper.getCurrentUser().getId());
		jobnotice.put("createDateTime", strnowTime);
		jobnotice.put("modifyUser", CodeHelper.getCurrentUser().getId());
		jobnotice.put("modifyDateTime", strnowTime);
		jobnotice.put("state", 99);
		notices.add(jobnotice);
		dbservices.saveOrupdateRecords("QhNotice", notices, null, false);

		return resultMap;
	}
	//获取用户详情
	@RequestMapping("/getUserView")
	public @ResponseBody Map getUserView(HttpServletRequest request) throws Exception {
		String sql="select id,Type,Uid,Pwd,OpenId,PicUrl,Inviter,NickName,Name,IsLogin,"
				+"Leav,u.Mobile,Sex,Birthday,IdCard,AlipayName,Alipay,Wechat,"
				+"TotalFund,AvailFund,BlockFund,IsNew,CreateUser,CreateDateTime,ModifyUser,SrcPla,"
				+"ModifyDateTime,State,(case Type when 'A' then '消费者' else '广告主' "
				+"end) AS TypeName,(case Leav when 1 then '一尾狐' when 2 then '二尾狐' when 3 then '三尾狐' when 4"
				+" then '四尾狐' when 5 then '五尾狐' when 6 then '六尾狐' when 7 then '七尾狐' when 8 then '八尾狐' when 9 then '九尾狐' else '' end) AS LeaveName,"
				+"(case State when 1 then '正常' when -1 then '停用' end) AS Staval,"
		        +"ifnull(a.ApprentCnt,0)ApprentCnt,ifnull(b.TeamCnt,0)TeamCnt,ifnull(c.TaskProfit,0)TaskProfit,ifnull(d.Rebate,0)Rebate,ifnull(e.InviterProfit,0)InviterProfit,ifnull(f.TaskCnt,0)TaskCnt,ifnull(g.ContiCnt,0)ContiCnt from qh_user u left join "
				+"(select Inviter as mobile,count(0)ApprentCnt from qh_user where islogin=1 group by Inviter)a on u.mobile=a.mobile left join "
				+"(select mobile,(select count(0) from qh_user where IsLogin=1 and LOCATE(a.id, InMobile)>0)TeamCnt from qh_user a group by mobile)b on u.mobile=b.mobile left join "
				+"(select CreateUser as mobile,sum(CashMoney)TaskProfit from qh_user_profit group by createuser)c on u.mobile=c.mobile left join "
				+"(select CreateUser as mobile,sum(CashMoney)Rebate from qh_user_profit where type='学徒' group by createuser)d on u.mobile=d.mobile left join "
				+"(select CreateUser as mobile,sum(CashMoney)InviterProfit from qh_user_profit where type='邀请' group by createuser)e on u.mobile=e.mobile left join "
				+"(select CreateUser as mobile,count(0)TaskCnt from qh_task_share where IsContinue=0 group by createuser)f on u.mobile=f.mobile left join "
				+"(select CreateUser as mobile,count(0)ContiCnt from qh_task_share where IsContinue=1 group by createuser)g on u.mobile=g.mobile"
				+" where u.id=?";
		JSONObject param = CodeHelper.getRequestParams(request);
		Integer id= param.getInteger("id");
		Integer i=0;
		HashMap<Integer, Object> intParamMap = new HashMap();
		intParamMap.put(i++, id);
		List<UserView> qhUsers = dbservices.findListBySql(sql, intParamMap, UserView.class);

		Map resultMap = new HashMap();
		resultMap.put("data", qhUsers.get(0));
		return resultMap;
	}
	//获取账户资金
	@RequestMapping("/getUserFund")
	public @ResponseBody Map getUserFund(HttpServletRequest request) {
		String sql = "select sum(TotalFund) from qh_user";
		Object TotalFund = dbservices.findUniqueBySql(sql, new HashMap());

		sql = "select sum(AvailFund) from qh_user";
		Object AvailFund = dbservices.findUniqueBySql(sql, new HashMap());

		sql = "select sum(BlockFund) from qh_user";
		Object BlockFund = dbservices.findUniqueBySql(sql, new HashMap());

		JSONObject jobj = new JSONObject();
		jobj.put("TotalFund", TotalFund);
		jobj.put("AvailFund", AvailFund);
		jobj.put("BlockFund", BlockFund);

		return jobj;
	}

	//检查用户名是否已存在
	@RequestMapping("/checkUser")
	public @ResponseBody Map checkUser(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		HashMap<Integer, Object> intParamMap = new HashMap<Integer, Object>();

		Integer i = 0;
		intParamMap.put(i++, param.getString("uid"));

		JSONObject jobj = new JSONObject();

		String sql = "select count(0) from qh_user where uid=?";
		Object cnt = dbservices.findUniqueBySql(sql, intParamMap);

		if (Integer.parseInt(cnt.toString()) > 0) {
			jobj.put("state", 0);
		} else {
			jobj.put("state", 1);
		}

		return jobj;
	}

	//获取用户
	@RequestMapping("/getUser")
	public @ResponseBody Map getUser(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		String type = param.getString("type");
		String name = param.getString("name");
		String hql = "SELECT * from (SELECT id,name,mobile,'a' as type from qh_user UNION";
		hql+=" select id,name,mobileno as mobile,'b' as type from tj_user where type='B')a where 1=1";
		if (!name.equals("")) {
			hql += " and (name like '%" + name + "%' or mobile like '%" + name + "%')";
		}
		if(!type.equals("")){
			hql+=" and type='"+type+"'";
		}
		JSONObject jobj = new JSONObject();

		List<QhNoticeUser> qhNoticeUsers = dbservices.findListBySql(hql, new HashMap(), QhNoticeUser.class);

		jobj.put("data", qhNoticeUsers);

		return jobj;
	}

	//发送系统公告
	@RequestMapping("/addNotice")
	public @ResponseBody Map addNotice(HttpServletRequest request) {
		Date nowTime = new Date();
		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strnowTime = time.format(nowTime);
		JSONObject param = CodeHelper.getRequestParams(request);
		String uid = param.getString("uid");
		String type = tool.getURLDecoderString(param.getString("type"));
		String usertype = param.getString("usertype");
		String title = tool.getURLDecoderString(param.getString("title"));
		String note = tool.getURLDecoderString(param.getString("note"));
		String[] struid = uid.split(",");
		String[] strusertype = usertype.split(",");
		for (int i=0;i<struid.length;i++) {
			List<JSONObject> notices = Lists.newArrayList();
			JSONObject jobj = new JSONObject();
			jobj.put("uid", struid[i]);
			jobj.put("userType", strusertype[i]);
			jobj.put("type", type);
			jobj.put("title", title);
			jobj.put("note", note);
			jobj.put("createUser", CodeHelper.getCurrentUser().getId());
			jobj.put("createDateTime", strnowTime);
			jobj.put("modifyUser", CodeHelper.getCurrentUser().getId());
			jobj.put("modifyDateTime", strnowTime);
			jobj.put("state", 99);
			notices.add(jobj);
			dbservices.saveOrupdateRecords("QhNotice", notices, null, false);

			QhUser qhUser=dbservices.getEntity(QhUser.class,Integer.valueOf(struid[i]));
			//极光推送
			ToolController.sendMsg(title,qhUser.getMobile());
		}
		JSONObject jobj = new JSONObject();
		jobj.put("state", 1);
		return jobj;
	}

	//获取用户姓名
	@RequestMapping("/getUserName")
	public @ResponseBody Map getUserName(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);

		JSONObject jobj = new JSONObject();
		QhUser qhUser = dbservices.getEntity(QhUser.class, param.getInteger("uid"));
		jobj.put("data", qhUser.getName());

		return jobj;
	}

	//获取用户手机
	@RequestMapping("/getUserMobile")
	public @ResponseBody Map getUserMobile(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);

		JSONObject jobj = new JSONObject();
		QhUser qhUser = dbservices.getEntity(QhUser.class, param.getInteger("uid"));
		jobj.put("mobile", qhUser.getMobile());

		return jobj;
	}

	//获取广告主姓名
	@RequestMapping("/getAdverName")
	public @ResponseBody Map getAdverName(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);

		JSONObject jobj = new JSONObject();

		User user = dbservices.getEntity(User.class, param.getInteger("uid"));

		jobj.put("name", user.getName());

		return jobj;
	}

	//获取试玩赚钱下载数
	@RequestMapping("/getDownNum")
	public @ResponseBody Map getDownNum(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		Integer i = 0;
		HashMap<Integer, Object> intParamMap = new HashMap();
		intParamMap.put(i++, param.getInteger("id"));
		String sql="select count(0) from qh_user_profit where TaskId=? and type='下载'";
		Object cnt = dbservices.findUniqueBySql(sql, intParamMap);

		JSONObject jobj = new JSONObject();
		jobj.put("cnt", cnt);
		return jobj;
	}


	@RequestMapping("/getDataChart")
	public @ResponseBody List getDataChart(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		List<JSONObject> jsonObjects = Lists.newArrayList();

		Integer i = 0;
		HashMap<Integer, Object> intParamMap = new HashMap();
		String readSql="",shareSql="";

		SimpleDateFormat fmtDate=new SimpleDateFormat("yyyy-MM-dd");
		Date nowTime=new Date();
		String strnowDate= fmtDate.format(nowTime);

		for(Integer y=0;y<24;y++){
			String Hdate=strnowDate+" "+y;
			if(y.toString().length()==1){
				Hdate=strnowDate+" 0"+y;
			}
			i = 0;
			intParamMap.clear();
			intParamMap.put(i++, Hdate);

			readSql = "select count(0) from qh_task_read where date_format(createdatetime,'%Y-%m-%d %H')=?";
			shareSql = "select count(0) from qh_task_share where date_format(createdatetime,'%Y-%m-%d %H')=? ";

			Object readCnt = dbservices.findUniqueBySql(readSql, intParamMap);
			Object shareCnt = dbservices.findUniqueBySql(shareSql, intParamMap);

			JSONObject jobj = new JSONObject();
			jobj.put("readCnt", readCnt);
			jobj.put("shareCnt", shareCnt);
			jobj.put("datetime", Hdate);
			jsonObjects.add(jobj);
		}

		return jsonObjects;
	}

	@RequestMapping("/getDataReport")
	public @ResponseBody List getDataReport(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		List<JSONObject> jsonObjects = Lists.newArrayList();

		List<Object[]> reportList= Lists.newArrayList();

		Integer i = 0;
		HashMap<Integer, Object> intParamMap = new HashMap();
		String readSql="",shareSql="",spendSql="";
		Date startDate=param.getDate("startDate");
		Date endDate=param.getDate("endDate");
		String date=param.getString("date");
		String id=param.getString("id");

		SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd");
		if(startDate!=null&&endDate!=null) {
			while (startDate.getTime() <= endDate.getTime()) {
				if (CodeHelper.getCurrentUser().getType().equals("A")) {
					i = 0;
					intParamMap.clear();
					intParamMap.put(i++, time.format(startDate));

					readSql = "select count(0) from qh_task_read where date_format(createdatetime,'%Y-%m-%d')=?";
					shareSql = "select count(0) from qh_task_share where date_format(createdatetime,'%Y-%m-%d')=? ";
					spendSql = "select sum(cashmoney) from qh_charg where date_format(createdatetime,'%Y-%m-%d')=? ";

					if(id!=null&&!id.equals("")){
						intParamMap.put(i++, id);
						readSql+=" and taskid=?";
						shareSql+=" and oid=?";
						spendSql+=" and taskid=?";
					}

				} else {
					i = 0;
					intParamMap.clear();
					intParamMap.put(i++, time.format(startDate));
					intParamMap.put(i++, CodeHelper.getCurrentUser().getId());
					readSql = "select count(0) from qh_task_read a inner join qh_task b on a.TaskId=b.id where date_format(a.createdatetime,'%Y-%m-%d')=? and b.Adver=?";
					shareSql = "select count(0) from qh_task_share a inner join qh_task b on a.oid=b.id where date_format(a.createdatetime,'%Y-%m-%d')=? and b.Adver=? ";
					spendSql = "select sum(a.cashmoney) from qh_charg a inner join qh_task b on a.TaskId=b.id where date_format(a.createdatetime,'%Y-%m-%d')=? and b.Adver=? ";

					if(id!=null&&!id.equals("")){
						intParamMap.put(i++, id);
						readSql+=" and a.taskid=?";
						shareSql+=" and a.oid=?";
						spendSql+=" and a.taskid=?";
					}
				}
				Object readCnt = dbservices.findUniqueBySql(readSql, intParamMap);
				Object shareCnt = dbservices.findUniqueBySql(shareSql, intParamMap);
				Object spend = dbservices.findUniqueBySql(spendSql, intParamMap);
				JSONObject jobj = new JSONObject();
				jobj.put("readCnt", readCnt);
				jobj.put("shareCnt", shareCnt);
				jobj.put("spend", spend);
				jobj.put("datetime", time.format(startDate));
				jsonObjects.add(jobj);
				Calendar calendar = new GregorianCalendar();
				calendar.setTime(startDate);
				calendar.add(calendar.DATE, 1);//把日期往后增加一天.整数往后推,负数往前移动
				startDate = calendar.getTime();//这个时间就是日期往后推一天的结果

				String per;
				if(Integer.valueOf(shareCnt.toString())==0){
					per="0.00%";
				}
				else{
					Float clickRate=Float.valueOf(readCnt.toString())/Float.valueOf(shareCnt.toString());
					clickRate=clickRate*10;
					DecimalFormat df = new DecimalFormat("#.00");
					per=df.format(clickRate)+"%";
				}

				Object[] arrReport=new Object[5];
				arrReport[0]=time.format(startDate);
				arrReport[1]=readCnt;
				arrReport[2]=shareCnt;
				arrReport[3]=per;
				arrReport[4]=spend==null?"0.0":spend;
				reportList.add(arrReport);

			}

			request.getSession().setAttribute("data", reportList);
		}

		if(date!=null){
			SimpleDateFormat fmtTime=new SimpleDateFormat("yyyy-MM-dd HH");
			for(Integer y=0;y<24;y++){
				String Hdate=date+" "+y;
				if(y.toString().length()==1){
					Hdate=date+" 0"+y;
				}
				if (CodeHelper.getCurrentUser().getType().equals("A")) {
					i = 0;
					intParamMap.clear();
					intParamMap.put(i++, Hdate);

					readSql = "select count(0) from qh_task_read where date_format(createdatetime,'%Y-%m-%d %H')=?";
					shareSql = "select count(0) from qh_task_share where date_format(createdatetime,'%Y-%m-%d %H')=? ";
					spendSql = "select sum(cashmoney) from qh_charg where date_format(createdatetime,'%Y-%m-%d %H')=? ";

					if(id!=null&&!id.equals("")){
						intParamMap.put(i++, id);
						readSql+=" and TaskId=?";
						shareSql+=" and oid=?";
						spendSql+=" and TaskId=?";
					}

				} else {
					i = 0;
					intParamMap.clear();
					intParamMap.put(i++, Hdate);
					intParamMap.put(i++, CodeHelper.getCurrentUser().getId());
					readSql = "select count(0) from qh_task_read a inner join qh_task b on a.TaskId=b.id where date_format(a.createdatetime,'%Y-%m-%d %H')=? and b.Adver=?";
					shareSql = "select count(0) from qh_task_share a inner join qh_task b on a.oid=b.id where date_format(a.createdatetime,'%Y-%m-%d %H')=? and b.Adver=? ";
					spendSql = "select sum(a.cashmoney) from qh_charg a inner join qh_task b on a.TaskId=b.id where date_format(a.createdatetime,'%Y-%m-%d %H')=? and b.Adver=? ";

					if(id!=null&&!id.equals("")){
						intParamMap.put(i++, id);
						readSql+=" and a.TaskId=?";
						shareSql+=" and a.oid=?";
						spendSql+=" and a.TaskId=?";
					}
				}
				Object readCnt = dbservices.findUniqueBySql(readSql, intParamMap);
				Object shareCnt = dbservices.findUniqueBySql(shareSql, intParamMap);
				Object spend = dbservices.findUniqueBySql(spendSql, intParamMap);
				JSONObject jobj = new JSONObject();
				jobj.put("readCnt", readCnt);
				jobj.put("shareCnt", shareCnt);
				jobj.put("spend", spend);
				jobj.put("datetime", Hdate);
				jsonObjects.add(jobj);

				String per;
				if(Integer.valueOf(shareCnt.toString())==0){
					per="0.00%";
				}
				else{
					Float clickRate=Float.valueOf(readCnt.toString())/Float.valueOf(shareCnt.toString());
					clickRate=clickRate*10;
					DecimalFormat df = new DecimalFormat("#.00");
					per=df.format(clickRate)+"%";
				}
				Object[] arrReport=new Object[5];
				arrReport[0]=Hdate;
				arrReport[1]=readCnt;
				arrReport[2]=shareCnt;
				arrReport[3]=per;
				arrReport[4]=spend==null?"0.0":spend;
				reportList.add(arrReport);
			}
			request.getSession().setAttribute("data", reportList);
		}

		return jsonObjects;
	}

	@RequestMapping("/getDataSta")
	public @ResponseBody Map getDataSta(HttpServletRequest request) {
		String sql = "select count(0) from qh_task_share where date_format(createdatetime,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d') ";
		Object shareCnt = dbservices.findUniqueBySql(sql, new HashMap());

		sql = "select count(0) from qh_task_read where date_format(createdatetime,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d') ";
		Object readCnt = dbservices.findUniqueBySql(sql, new HashMap());

		sql = "select sum(cashMoney) from qh_charg where date_format(createdatetime,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d') ";
		Object conMoney = dbservices.findUniqueBySql(sql, new HashMap());

		Map resultMap = new HashMap();
		resultMap.put("shareCnt", shareCnt);
		resultMap.put("readCnt", readCnt);
		resultMap.put("conMoney", conMoney);
		return resultMap;
	}

	@RequestMapping("/chkUserCode")
	public @ResponseBody Map chkUserCode(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		Integer i = 0;
		HashMap<Integer, Object> intParamMap = new HashMap();
		String hql="from User where userCode=?";
		intParamMap.put(i++, param.getString("userCode"));
		List result = dbservices.findListByHql(hql, intParamMap);
		JSONObject jobj = new JSONObject();
		if(result.size()>0){
			jobj.put("state",1);
		}
		else{
			jobj.put("state", 0);
		}
		return jobj;
	}

	@RequestMapping("/editUserFund")
	public @ResponseBody Map editUserFund(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		Integer id=param.getInteger("id");
		Double money=param.getDouble("money");
        User user=dbservices.getEntity(User.class, id);
		Double TotalFund=user.getTotalFund()+money;
		Double AvailFund=user.getAvailFund()+money;
		user.setTotalFund(TotalFund);
		user.setAvailFund(AvailFund);
		dbservices.update(user);
		JSONObject jobj = new JSONObject();
		jobj.put("state",1);
		return jobj;
	}

	//获取广告主信息
	@RequestMapping("/getAdver")
	public @ResponseBody List getAdver(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		String name = param.getString("name");

		String hql="from User where type='B'";
		if (name!=null&&!name.equals("")) {
			hql += " and name like '%" + name + "%'";
		}
		List<User> users= dbservices.findListByHql(hql, new HashMap());

		List<JSONObject> jsonObjects = Lists.newArrayList();
		for(User user:users){
			JSONObject jobj = new JSONObject();
			jobj.put("id",user.getId());
			jobj.put("name",user.getName());
			jsonObjects.add(jobj);
		}
		return jsonObjects;
	}
    //检查任务投放金额是否大于可用余额
	@RequestMapping("/chkAvailFundByTask")
	public @ResponseBody Map chkAvailFundByTask(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
        Integer adver=param.getInteger("adver");
        Double investAmount=param.getDouble("investAmount");
		User user=dbservices.getEntity(User.class, adver);
		JSONObject jobj = new JSONObject();
		if(user.getAvailFund()>=investAmount){
			jobj.put("state",1);
		}
		else{
			jobj.put("state",0);
		}
		return jobj;
	}
	//添加广告主财务记录
	public void addAdverAccount(Integer adver,Double investAmount) {
		Date nowTime=new Date();
		SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strnowTime= time.format(nowTime);

		List<JSONObject> jsonAdverAccount = Lists.newArrayList();
		JSONObject jobAdverAccount = new JSONObject();
		jobAdverAccount.put("uid", adver);
		jobAdverAccount.put("type", "任务投放");
		jobAdverAccount.put("deposit", 0);
		jobAdverAccount.put("expend", investAmount);
		jobAdverAccount.put("createUser", CodeHelper.getCurrentUser().getId());
		jobAdverAccount.put("createDateTime", strnowTime);
		jobAdverAccount.put("modifyUser", CodeHelper.getCurrentUser().getId());
		jobAdverAccount.put("modifyDateTime", strnowTime);
		jobAdverAccount.put("state", 99);
		jsonAdverAccount.add(jobAdverAccount);
		dbservices.saveOrupdateRecords("QhAdverAccount", jsonAdverAccount, null, false);

		User user=dbservices.getEntity(User.class,adver);
		Double TotalFund=user.getTotalFund()-investAmount;
		Double AvailFund=user.getAvailFund()-investAmount;
		user.setTotalFund(TotalFund);
		user.setAvailFund(AvailFund);
		dbservices.update(user);
	}

	//广告主今天花费
	@RequestMapping("/getExpend")
	public @ResponseBody Map getExpend(HttpServletRequest request) {
		Integer i=0;
		HashMap<Integer, Object> intParamMap = new HashMap();
		intParamMap.put(i++, CodeHelper.getCurrentUser().getId());
        String sql="select sum(Expend) from qh_adver_account where date_format(createdatetime,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d') and uid=?";
		Object oExpend=dbservices.findUniqueBySql(sql,intParamMap);
		JSONObject jobj = new JSONObject();
		jobj.put("expend", oExpend);
		return jobj;
	}

	//修改充值状态
	@RequestMapping("/rechargeStateEdit")
	public @ResponseBody Map rechargeStateEdit(HttpServletRequest request) {
		Date nowTime = new Date();
		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strnowTime = time.format(nowTime);

		JSONObject param = CodeHelper.getRequestParams(request);
		Map resultMap = new HashMap();
		List<JSONObject> mathQuryask = Lists.newArrayList();
		JSONObject jobj = new JSONObject();

		jobj.put("id", param.getInteger("id"));
		jobj.put("state", param.getInteger("state"));
		jobj.put("modifyUser", CodeHelper.getCurrentUser().getId());
		jobj.put("modifyDateTime", strnowTime);
		mathQuryask.add(jobj);
		String returnId = dbservices.saveOrupdateRecords("QhAdverAccount", mathQuryask, null, false);
		resultMap.put("state", "1");

		return resultMap;
	}

	//修改工具提现状态
	@RequestMapping("/toolCashStateEdit")
	public @ResponseBody Map toolCashStateEdit(HttpServletRequest request) {
		Date nowTime = new Date();
		SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strnowTime = time.format(nowTime);

		JSONObject param = CodeHelper.getRequestParams(request);
		Map resultMap = new HashMap();
		List<JSONObject> mathQuryask = Lists.newArrayList();
		JSONObject jobj = new JSONObject();

		jobj.put("id", param.getInteger("id"));
		jobj.put("state", param.getInteger("state"));
		jobj.put("modifyUser", CodeHelper.getCurrentUser().getId());
		jobj.put("modifyDateTime", strnowTime);
		mathQuryask.add(jobj);
		String returnId = dbservices.saveOrupdateRecords("QhToolCash", mathQuryask, null, false);
		resultMap.put("state", "1");

		return resultMap;
	}

	//广告主首页
	@RequestMapping("/getAdverIndexInfo")
	public @ResponseBody Map getAdverIndexInfo(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		Integer i=0;
		HashMap<Integer, Object> intParamMap = new HashMap();
		intParamMap.put(i++, CodeHelper.getCurrentUser().getId());
		intParamMap.put(i++,param.getString("staDate"));

		String sql="";

		sql="select sum(Expend) from qh_adver_account where uid=? and date_format(createdatetime,'%Y-%m-%d')=?";
		Object oExpend=dbservices.findUniqueBySql(sql,intParamMap);
		JSONObject jobj = new JSONObject();
		jobj.put("expend", oExpend);

		sql = "select count(0) from qh_task_read a inner join qh_task b on a.TaskId=b.id where b.Adver=? and date_format(a.createdatetime,'%Y-%m-%d')=?";
		Object oReadCnt=dbservices.findUniqueBySql(sql,intParamMap);
		jobj.put("readcnt", oReadCnt);

		sql = "select count(0) from qh_user_operlog a inner join qh_task b on a.oid=b.id where b.Adver=? and date_format(a.createdatetime,'%Y-%m-%d')=? and a.funname='分享'";
		Object oShareCnt=dbservices.findUniqueBySql(sql,intParamMap);
		jobj.put("sharecnt", oShareCnt);

		sql="select count(0) from qh_task where adver=? and state=99 and date_format(createdatetime,'%Y-%m-%d')=?";
		Object oTaskCnt=dbservices.findUniqueBySql(sql,intParamMap);
		jobj.put("taskcnt1", oTaskCnt);

		sql="select count(0) from qh_task where adver=? and state=-2 and date_format(createdatetime,'%Y-%m-%d')=?";
		oTaskCnt=dbservices.findUniqueBySql(sql,intParamMap);
		jobj.put("taskcnt2", oTaskCnt);

		sql = "select count(0) from qh_task where adver=? and state=2 and date_format(createdatetime,'%Y-%m-%d')=?";
		oTaskCnt=dbservices.findUniqueBySql(sql,intParamMap);
		jobj.put("taskcnt3", oTaskCnt);

		sql = "select count(0) from qh_task where adver=? and date_format(createdatetime,'%Y-%m-%d')=?";
		oTaskCnt=dbservices.findUniqueBySql(sql,intParamMap);
		jobj.put("taskcnt4", oTaskCnt);

		return jobj;
	}

	@RequestMapping("/getTaskShareById")
	public @ResponseBody Map getTaskShareById(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		Integer i=0;
		HashMap<Integer, Object> intParamMap = new HashMap();
		intParamMap.put(i++,param.getInteger("id"));

		JSONObject jobj = new JSONObject();
		Object obj=new Object();

		String sql="";
		sql = "select count(0) from qh_user_operlog a where a.oid=? and a.funname='分享'";
		obj=dbservices.findUniqueBySql(sql,intParamMap);
		jobj.put("sharecnt", obj==null?0:obj);

		sql = "select count(0) from qh_task_read a where a.TaskId=?";
		obj=dbservices.findUniqueBySql(sql,intParamMap);
		jobj.put("readcnt", obj==null?0:obj);

		sql="select sum(CashMoney) from qh_charg where TaskId=?";
		obj=dbservices.findUniqueBySql(sql,intParamMap);
		jobj.put("spend", obj == null?0:obj);
		return jobj;
	}

	//添加广告操作日志
	@RequestMapping("/addTaskOperLog")
	public void addTaskOperLog(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		Date nowTime=new Date();
		SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strnowTime= time.format(nowTime);

		List<JSONObject> jsonQhTaskOperLog= Lists.newArrayList();
		JSONObject jobQhTaskOperLog = new JSONObject();
		jobQhTaskOperLog.put("object", param.getString("object"));
		jobQhTaskOperLog.put("content",param.getString("content"));
		jobQhTaskOperLog.put("modifyCont", param.getString("modifyCont"));
		jobQhTaskOperLog.put("createUser", CodeHelper.getCurrentUser().getId());
		jobQhTaskOperLog.put("createDateTime", strnowTime);
		jobQhTaskOperLog.put("modifyUser", CodeHelper.getCurrentUser().getId());
		jobQhTaskOperLog.put("modifyDateTime", strnowTime);
		jobQhTaskOperLog.put("state", 99);
		jsonQhTaskOperLog.add(jobQhTaskOperLog);
		dbservices.saveOrupdateRecords("QhTaskOperLog", jsonQhTaskOperLog, null, false);
	}

	//获取基础参数
	@RequestMapping("/getQhSysPar")
	public @ResponseBody Object getQhSysPar(HttpServletRequest request) {
        QhSysPar qhSysPar=dbservices.getEntity(QhSysPar.class,1);
		return qhSysPar;
	}
	//设置分享地址
	@RequestMapping("/setShareUrl")
	public @ResponseBody Map setShareUrl(HttpServletRequest request) {
		StringBuffer url = request.getRequestURL();
		String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getContextPath()).append("/").toString();

		JSONObject param = CodeHelper.getRequestParams(request);
		Integer id=param.getInteger("id");

		QhTask qhTask=dbservices.getEntity(QhTask.class, id);

		String shareUrl=tempContextUrl+"app/read.jsp?taskid="+id;
		qhTask.setShareUrl(shareUrl);
		dbservices.update(qhTask);

		JSONObject jobj = new JSONObject();
		jobj.put("state",1);

		return jobj;
	}

	//获取消息
	@RequestMapping("/getNoticeList")
	public @ResponseBody List getNoticeList(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		String type=param.getString("type");
		Integer i=0;
		HashMap<Integer, Object> intParamMap = new HashMap();
		intParamMap.put(i++, CodeHelper.getCurrentUser().getId().toString());
		String hql="from QhNotice where uid=?";
		if(!type.equals("")){
			hql+=" and type=?";
			intParamMap.put(i++,type);
		}
		List<QhNotice> qhNotices = dbservices.findListByHql(hql, intParamMap);

		return qhNotices;
	}

	//获取消息
	@RequestMapping("/setCommission")
	public @ResponseBody Map setCommission(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		Integer id=param.getInteger("id");
		/*Double Commission=param.getDouble("Commission");
		Double RealCommission=param.getDouble("RealCommission");
		Double ShareProfit=param.getDouble("ShareProfit");
		Double ReadProfit=param.getDouble("ReadProfit");
		qhTask.setCommission(Commission);
		qhTask.setRealCommission(RealCommission);
		qhTask.setShareProfit(ShareProfit);
		qhTask.setReadProfit(ReadProfit);*/
		QhTask qhTask=dbservices.getEntity(QhTask.class,id);
		qhTask.setState(1);
		dbservices.update(qhTask);
		JSONObject jobj = new JSONObject();
		jobj.put("state", 1);

		return jobj;
	}

	//获取消息
	@RequestMapping("/replyFeedback")
	public @ResponseBody Map replyFeedback(HttpServletRequest request) {
		Date nowTime=new Date();
		SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strnowTime= time.format(nowTime);

		JSONObject param = CodeHelper.getRequestParams(request);
		Integer id=param.getInteger("id");
		String replyNote=tool.getURLDecoderString(param.getString("replyNote"));
		QhFeedback qhFeedback=dbservices.getEntity(QhFeedback.class, id);
		qhFeedback.setReplyNote(replyNote);
		dbservices.update(qhFeedback);
		JSONObject jobj = new JSONObject();
		jobj.put("state", 1);

		String msg="回复反馈「"+qhFeedback.getNote()+"」";
		ToolController.sendMsg(msg, qhFeedback.getCreateUser());

		Integer i=0;
		HashMap<Integer, Object> intParamMap = new HashMap();
		intParamMap.put(i++, qhFeedback.getCreateUser());
		String hql="from QhUser where mobile=?";
		List<QhUser> qhUsers=dbservices.findListByHql(hql,intParamMap);

		List<JSONObject> notices = Lists.newArrayList();
		JSONObject jobnotice = new JSONObject();
		jobnotice.put("uid",qhUsers.get(0).getId());
		jobnotice.put("userType", "a");
		jobnotice.put("type", "系统消息");
		jobnotice.put("title", msg);
		jobnotice.put("note", replyNote);
		jobnotice.put("createUser", CodeHelper.getCurrentUser().getId());
		jobnotice.put("createDateTime", strnowTime);
		jobnotice.put("modifyUser", CodeHelper.getCurrentUser().getId());
		jobnotice.put("modifyDateTime", strnowTime);
		jobnotice.put("state", 99);
		notices.add(jobnotice);
		dbservices.saveOrupdateRecords("QhNotice", notices, null, false);

		return jobj;
	}

	@RequestMapping("/getShareInfo")
	public @ResponseBody Map getShareInfo(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		Integer uid=param.getInteger("uid");
		QhUser qhUser=dbservices.getEntity(QhUser.class, uid);
		String mobile=qhUser.getMobile();
		Integer i=0;
		HashMap<Integer, Object> intParamMap = new HashMap();
		intParamMap.put(i++,mobile);
		String sql="select count(0) from qh_task_share where iscontinue=0 and createuser=?";
		Object sharenum1=dbservices.findUniqueBySql(sql,intParamMap);

		sql="select count(0) from qh_task_share where createuser=?";
		Object sharenum2=dbservices.findUniqueBySql(sql,intParamMap);

		sql="select sum(CashMoney) from qh_user_profit where type='分享' and createuser=?";
		Object shareprofit=dbservices.findUniqueBySql(sql,intParamMap);

		sql="select sum(CashMoney) from qh_user_profit where type='阅读' and createuser=?";
		Object readprofit=dbservices.findUniqueBySql(sql,intParamMap);

		JSONObject jobj = new JSONObject();
		jobj.put("sharenum1", sharenum1==null?0:sharenum1);
		jobj.put("sharenum2", sharenum2==null?0:sharenum2);
		jobj.put("shareprofit", shareprofit==null?0:shareprofit);
		jobj.put("readprofit", readprofit==null?0:readprofit);

		return jobj;
	}
	@RequestMapping("/getBusinessList")
	public @ResponseBody Map getBusinessList(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		String createdatetime=param.getString("createdatetime");

		String jhSql1="select count(0) from qh_user_operlog where srcpla='qf_8' and funname='激活'";
		String jhSql2="select count(0) from qh_user_operlog where srcpla='qf_13' and funname='激活'";
		String jhSql3="select count(0) from qh_user_operlog where srcpla='qf_14' and funname='激活'";

		String regSql1="select count(0) from qh_user where srcpla='qf_8' ";
		String regSql2="select count(0) from qh_user where srcpla='qf_13' ";
		String regSql3="select count(0) from qh_user where srcpla='qf_14' ";

		String downSql1="select count(0) from qh_user_operlog where srcpla='qf_8' and funname='下载'";
		String downSql2="select count(0) from qh_user_operlog where srcpla='qf_13' and funname='下载'";
		String downSql3="select count(0) from qh_user_operlog where srcpla='qf_14' and funname='下载'";

		String hySql1="select count(0) from qh_user_operlog where srcpla='qf_8' and funname='活跃'";
		String hySql2="select count(0) from qh_user_operlog where srcpla='qf_13' and funname='活跃'";
		String hySql3="select count(0) from qh_user_operlog where srcpla='qf_14' and funname='活跃'";

		if(createdatetime!=""&&createdatetime!=null){
			jhSql1+=" and DATE_FORMAT(createdatetime,'%Y-%m-%d')='"+createdatetime+"'";
			jhSql2+=" and DATE_FORMAT(createdatetime,'%Y-%m-%d')='"+createdatetime+"'";
			jhSql3+=" and DATE_FORMAT(createdatetime,'%Y-%m-%d')='"+createdatetime+"'";
			regSql1+=" and DATE_FORMAT(createdatetime,'%Y-%m-%d')='"+createdatetime+"'";
			regSql2+=" and DATE_FORMAT(createdatetime,'%Y-%m-%d')='"+createdatetime+"'";
			regSql3+=" and DATE_FORMAT(createdatetime,'%Y-%m-%d')='"+createdatetime+"'";
			downSql1+=" and DATE_FORMAT(createdatetime,'%Y-%m-%d')='"+createdatetime+"'";
			downSql2+=" and DATE_FORMAT(createdatetime,'%Y-%m-%d')='"+createdatetime+"'";
			downSql3+=" and DATE_FORMAT(createdatetime,'%Y-%m-%d')='"+createdatetime+"'";
			hySql1+=" and DATE_FORMAT(createdatetime,'%Y-%m-%d')='"+createdatetime+"'";
			hySql2+=" and DATE_FORMAT(createdatetime,'%Y-%m-%d')='"+createdatetime+"'";
			hySql3+=" and DATE_FORMAT(createdatetime,'%Y-%m-%d')='"+createdatetime+"'";
		}
		Object jhCnt1=dbservices.findUniqueBySql(jhSql1,new HashMap());
		Object jhCnt2=dbservices.findUniqueBySql(jhSql2,new HashMap());
		Object jhCnt3=dbservices.findUniqueBySql(jhSql3,new HashMap());
		Object regCnt1=dbservices.findUniqueBySql(regSql1,new HashMap());
		Object regCnt2=dbservices.findUniqueBySql(regSql2,new HashMap());
		Object regCnt3=dbservices.findUniqueBySql(regSql3,new HashMap());
		Object downCnt1=dbservices.findUniqueBySql(downSql1,new HashMap());
		Object downCnt2=dbservices.findUniqueBySql(downSql2,new HashMap());
		Object downCnt3=dbservices.findUniqueBySql(downSql3,new HashMap());
		Object hyCnt1=dbservices.findUniqueBySql(hySql1,new HashMap());
		Object hyCnt2=dbservices.findUniqueBySql(hySql2,new HashMap());
		Object hyCnt3=dbservices.findUniqueBySql(hySql3,new HashMap());

		JSONObject jobj = new JSONObject();
		jobj.put("jhCnt1", jhCnt1==null?0:jhCnt1);
		jobj.put("jhCnt2", jhCnt2==null?0:jhCnt2);
		jobj.put("jhCnt3", jhCnt3==null?0:jhCnt3);
		jobj.put("regCnt1", regCnt1==null?0:regCnt1);
		jobj.put("regCnt2", regCnt2==null?0:regCnt2);
		jobj.put("regCnt3", regCnt3==null?0:regCnt3);
		jobj.put("downCnt1", downCnt1==null?0:downCnt1);
		jobj.put("downCnt2", downCnt2==null?0:downCnt2);
		jobj.put("downCnt3", downCnt3==null?0:downCnt3);
		jobj.put("hyCnt1", hyCnt1==null?0:hyCnt1);
		jobj.put("hyCnt2", hyCnt2==null?0:hyCnt2);
		jobj.put("hyCnt3", hyCnt3==null?0:hyCnt3);

		return jobj;
	}

	@RequestMapping("/getActiveCnt")
	public @ResponseBody Map getActiveCnt(HttpServletRequest request) {
		JSONObject param = CodeHelper.getRequestParams(request);
		String SrcPla=param.getString("SrcPla");
		Integer i=0;
		HashMap<Integer, Object> intParamMap = new HashMap();
		intParamMap.put(i++,param.getString("date1"));

		String strSql1="select count(0) from qh_user where islogin=1 and DATE_FORMAT(createdatetime,'%Y-%m-%d')=?";
		if(SrcPla!=null&&SrcPla!=""){
			strSql1+=" and SrcPla=?";
			intParamMap.put(i++,SrcPla);
		}
		Object regCnt=dbservices.findUniqueBySql(strSql1,intParamMap);

		i=0;
		intParamMap.clear();
		intParamMap.put(i++, param.getString("date1"));
		intParamMap.put(i++,param.getString("date2"));
		String strSql2="select count(0) from qh_user a inner join qh_user_operlog b on a.mobile=b.createuser where a.islogin=1 and b.funname='活跃' and DATE_FORMAT(a.createdatetime,'%Y-%m-%d')=? and DATE_FORMAT(b.createdatetime,'%Y-%m-%d')=?";
		if(SrcPla!=null&&SrcPla!=""){
			strSql2+=" and b.SrcPla=?";
			intParamMap.put(i++,SrcPla);
		}
		Object acCnt=dbservices.findUniqueBySql(strSql2,intParamMap);

		JSONObject jobj = new JSONObject();
		jobj.put("regCnt", regCnt==null?0:regCnt);
		jobj.put("acCnt", acCnt==null?0:acCnt);

		return jobj;
	}

}
